define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'editable', 'echarts', 'echarts-theme'], function ($, undefined, Backend, Table, Form, undefined, Echarts, undefined) {

    var Controller = {
        index: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'jdy/device/index',
                    add_url: '',
                    edit_url: 'jdy/device/edit',
                    del_url: '',
                    multi_url: 'jdy/device/multi',
                    table: 'jdy_device',
                }
            });

            var table = $("#table");

            //在普通搜索渲染後
            table.on('post-common-search.bs.table', function (event, table) {
                //var form = $("form", table.$commonsearch);
                //$("input[name='smallcategory.name']", form).addClass("selectpage").data("source", "jdy/smallcategory/index").data("primaryKey", "name").data("field", "smallcategory_id").data("orderBy", "id desc");
                //Form.events.selectpage(form);
            });

            table.on('post-body.bs.table', function (e, settings, json, xhr) {
                $(".txsz").data("area", ["100%", "100%"]);
            });


            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: true,
                showExport: false,
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('Id')},
                        //{field: 'room_id', title: __('Room_id')},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'addtabs',
                                    title: __('記錄詳情'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa-dashboard',
                                    url: 'jdy/device/detail'
                                },
                                {
                                    name: 'addtabs',
                                    title: __('提醒設置'),
                                    classname: 'btn btn-xs btn-primary btn-dialog txsz',
                                    icon: 'fa fa-opencart',
                                    url: 'jdy/device/txsz',
                                    callback: function (data) {
                                        //Layer.alert("接收到回傳數據：" + JSON.stringify(data), {title: "回傳數據"});
                                    }
                                },
                            ],
                            formatter: Table.api.formatter.operate
                        },
                        {field: 'name', title: __('裝置代號'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        {field: 'online', title: __('Online'), searchList: {"0":__('離線'),"1":__('在線')}, formatter: Controller.api.formatter.zxstatus},
                        {field: 'online_time', title: __('持續時間'), operate:false, formatter: Controller.api.formatter.onlinetime},
                        {field: 'smallcategory.name', title: __('類型'), operate:false},
                        {field: 'smallcategory_id', title: __('類型'), visible: false, addClass: "selectpage", extend: "data-source='jdy/smallcategory/index1' data-field='name'"},
                        {field: 'anchangname', title: __('案場名称'), operate:false},
                        {field: 'room.name', title: __('Room.name'), operate:false},
                        {field: 'deviceid', title: __('裝置SN')},
                        {field: 'selfname', title: __('裝置名稱'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                       //{field: 'category', title: __('Category')},
                        //{field: 'type', title: __('Type')},

                        //{field: 'pid', title: __('Pid')},
                        //{field: 'place', title: __('Place')},
                        //{field: 'version', title: __('Version')},
                        //{field: 'iconVer', title: __('Iconver')},
                        //{field: 'iconUrl', title: __('Iconurl'), formatter: Table.api.formatter.url},
                        //{field: 'center', title: __('Center')},
                        //{field: 'deviceIp', title: __('Deviceip')},
                        //{field: 'routeMacString', title: __('Routemacstring')},
                        //{field: 'subType', title: __('Subtype')},
                        //{field: 'state', title: __('State')},
                        //{field: 'updatenum', title: __('Updatenum')},
                        //{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:false, addclass:'datetimerange', formatter: Table.api.formatter.datetime},

                        ////{field: 'room.id', title: __('Room.id')},
                        //{field: 'room.building_id', title: __('Room.building_id')},
                        //{field: 'room.roomid', title: __('Room.roomid')},
                        //{field: 'room.name', title: __('Room.name')},
                        //{field: 'room.account', title: __('Room.account')},
                        //{field: 'room.password', title: __('Room.password')},
                        //{field: 'room.floorNo', title: __('Room.floorno')},
                        //{field: 'room.optId', title: __('Room.optid')},
                        //{field: 'room.padId', title: __('Room.padid')},
                        //{field: 'room.updatenum', title: __('Room.updatenum')},
                        //{field: 'room.create_time', title: __('Room.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'room.update_time', title: __('Room.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}

                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        index1: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'jdy/device/index1',
                    add_url: '',
                    edit_url: 'jdy/device/edit',
                    del_url: '',
                    multi_url: 'jdy/device/multi',
                    table: 'jdy_device',
                }
            });

            var table = $("#table");

            //在普通搜索渲染後
            table.on('post-common-search.bs.table', function (event, table) {
                //var form = $("form", table.$commonsearch);
                //$("input[name='smallcategory.name']", form).addClass("selectpage").data("source", "jdy/smallcategory/index").data("primaryKey", "name").data("field", "smallcategory_id").data("orderBy", "id desc");
                //Form.events.selectpage(form);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,//不顯示搜索框
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        //{field: 'id', title: __('Id')},
                        //{field: 'room_id', title: __('Room_id')},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'addtabs',
                                    title: __('記錄詳情'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa-dashboard',
                                    url: 'jdy/device/detail'
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        },
                        {field: 'deviceid', title: __('裝置SN')},
                        {field: 'room.name', title: __('Room.name'), operate:false},
                        {field: 'name', title: __('裝置代號'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        {field: 'selfname', title: __('裝置名稱'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        //{field: 'category', title: __('Category')},
                        //{field: 'type', title: __('Type')},
                        {field: 'smallcategory.name', title: __('類型'), operate:false},
                        {field: 'smallcategory_id', title: __('類型'), visible: false, addClass: "selectpage", extend: "data-source='jdy/smallcategory/index2' data-field='name'"},

                        //{field: 'pid', title: __('Pid')},
                        //{field: 'place', title: __('Place')},
                        //{field: 'version', title: __('Version')},
                        {field: 'online', title: __('Online'), searchList: {"0":__('離線'),"1":__('在線')}, formatter: Controller.api.formatter.zxstatus},
                        //{field: 'iconVer', title: __('Iconver')},
                        //{field: 'iconUrl', title: __('Iconurl'), formatter: Table.api.formatter.url},
                        //{field: 'center', title: __('Center')},
                        //{field: 'deviceIp', title: __('Deviceip')},
                        //{field: 'routeMacString', title: __('Routemacstring')},
                        //{field: 'subType', title: __('Subtype')},
                        //{field: 'state', title: __('State')},
                        //{field: 'updatenum', title: __('Updatenum')},
                        //{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'online_time', title: __('持續時間'), operate:false, formatter: Controller.api.formatter.onlinetime},

                        ////{field: 'room.id', title: __('Room.id')},
                        //{field: 'room.building_id', title: __('Room.building_id')},
                        //{field: 'room.roomid', title: __('Room.roomid')},
                        //{field: 'room.name', title: __('Room.name')},
                        //{field: 'room.account', title: __('Room.account')},
                        //{field: 'room.password', title: __('Room.password')},
                        //{field: 'room.floorNo', title: __('Room.floorno')},
                        //{field: 'room.optId', title: __('Room.optid')},
                        //{field: 'room.padId', title: __('Room.padid')},
                        //{field: 'room.updatenum', title: __('Room.updatenum')},
                        //{field: 'room.create_time', title: __('Room.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'room.update_time', title: __('Room.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}

                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        detail0: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'jdy/device/detail0',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                    table: 'jdy_device',
                }
            });

            var table = $("#table");

            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,//不顯示搜索框
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        //{field: 'devhistoryid', title: __('Devhistoryid'), operate:false},
                        //{field: 'sn', title: __('Sn'), operate:false},
                        {field: 'd', title: __('日期'), operate:false},
                        {field: 't', title: __('時間'), operate:false},
                        {field: 'online', title: __('在線狀態'), operate:false, formatter: Controller.api.formatter.zxstatus},
                        {field: 'state', title: __('狀態'), operate:false},
                        {field: 'dt', title: __('持續時間'), operate:false},
                        {field: 'dateInfo', title: __('日期範圍'), visible:false, defaultValue:Controller.api.defaultdate2(), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        chart0: function () {
            $("#c-submit").click(function (e) {
                //不是所有的input都提交
                //Backend.api.toastr.success("提交");
                var formdata = $("#search-form").serialize();
                if (!formdata) {
                    Backend.api.toastr.error("請選擇區域日期");
                    return;
                }
                var x = $("#search-form").serializeArray();
                var row = new Array();
                $.each(x, function (i, field) {
                    row[field.name] = field.value;
                    if (field.name == "dateInfo") {

                    }
                });

                var url = 'jdy/device/chart0/ids/' + Statsdata.ids + '?ref=addtabs';
                Backend.api.ajax({
                    url: url,
                    data: formdata
                }, function (data, ret) {
                    console.log(data);
                    //Backend.api.toastr.success(data);
                    Statsdata.list = data;
                    Controller.showechart0();
                });

            });

            Controller.showechart0();

            Controller.api.bindevent();
        },
        detail: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'jdy/device/detail',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                    table: 'jdy_device',
                }
            });

            var table = $("#table");

            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,//不顯示搜索框
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {field: 'name', title: __('裝置代號'), operate:false},
                        {field: 'online', title: __('在線狀態'), operate:false, formatter: Controller.api.formatter.zxstatus},
                        {field: 'dt', title: __('持續時間'), operate:false},
                        {field: 'create_time', title: __('記錄日期'), defaultValue:Controller.api.defaultdate2(), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        chart: function () {
            updatechart("");

            $("#c-submit").click(function (e) {
                //不是所有的input都提交
                //Backend.api.toastr.success("提交");
                var formdata = $("#search-form").serialize();
                if (!formdata) {
                    Backend.api.toastr.error("請選擇區域日期");
                    return;
                }
                var x = $("#search-form").serializeArray();
                var row = new Array();
                $.each(x, function (i, field) {
                    row[field.name] = field.value;
                    if (field.name == "dateInfo") {

                    }
                });

                updatechart(formdata);

            });

            function updatechart(formdata) {
                var url = 'jdy/device/chart/ids/' + Statsdata.ids + '?ref=addtabs';
                Backend.api.ajax({
                    url: url,
                    data: formdata
                }, function (data, ret) {
                    console.log(data);
                    //Backend.api.toastr.success(data);
                    Statsdata.list = data;
                    Controller.showechart();
                });
            }

            Controller.showechart();

            Controller.api.bindevent();
        },
        showechart: function () {
            Date.prototype.Format = function (fmt) {
                var o = {
                    "M+": this.getMonth() + 1, //月份
                    "d+": this.getDate(), //日
                    "H+": this.getHours(), //小時
                    "m+": this.getMinutes(), //分
                    "s+": this.getSeconds(), //秒
                    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                    "S": this.getMilliseconds() //毫秒
                };
                if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            };

            var myChart = Echarts.init(document.getElementById('echart'), 'walden');

            var datelist = [];
            var size = Statsdata.list.length;
            if (size > 0) {
                var i = 0;
                for (i = 0; i < Statsdata.list.length; i++) {
                    var d = Statsdata.list[i].d;
                    if (datelist.indexOf(d) < 0) {
                        datelist.push(d);
                    }
                }
            }

            var now = new Date();//當前日期
            var data = [];

            var device_id = Statsdata.row.id;

            Echarts.util.each(Statsdata.list, function (w, index) {

                var date = new Date(w.start * 1000);
                var day = date.getDay();//0~6 一周

                var color = '#00aa00';
                if (day == 0 || day == 6) {
                    if (device_id == w.device_id) {
                        color = '#aaaa00';
                    } else {
                        color = '#aa00bb';
                    }
                } else {
                    if (device_id == w.device_id) {
                        color = '#00aa00';
                    } else {
                        color = '#0000bb';
                    }
                }

                var index0 = 0;
                for (i = 0; i < datelist.length; i++) {
                    if (datelist[i] == w.d) {
                        index0 = i;
                        break;
                    }
                }

                data.push({
                    name: "(id=" + w.id + ") " + w.dt,
                    value: [
                        index0,
                        w.x0,
                        w.x1,
                        w.info
                    ],
                    itemStyle: {
                        normal: {
                            color: color
                        }
                    }
                });

                if (index == 0) {
                    //console.log(w.start + " - " + w.start0);
                    //console.log(data);
                }


            });

            function renderItem(params, api) {
                var categoryIndex = api.value(0);
                var start = api.coord([api.value(1), categoryIndex]);
                var end = api.coord([api.value(2), categoryIndex]);
                var height = api.size([0, 1])[1] * 0.6;

                var rectShape = Echarts.graphic.clipRectByRect({
                    x: start[0],
                    y: start[1] - height / 2,
                    width: end[0] - start[0],
                    height: height
                }, {
                    x: params.coordSys.x,
                    y: params.coordSys.y,
                    width: params.coordSys.width,
                    height: params.coordSys.height
                });

                return rectShape && {
                        type: 'rect',
                        shape: rectShape,
                        style: api.style()
                    };
            }

            option = {
                tooltip: {
                    formatter: function (params) {
                        return params.marker + params.name + ' [' + params.value[3] + "]";
                        //return params.name;
                    }
                },
                title: {
                    text: Statsdata.row.anchang.name + ">" + Statsdata.row.name + " - " + Statsdata.row.selfname + "[" + Statsdata.row.deviceid + "] + " + Statsdata.row.glsb,
                    left: 'center'
                },
                toolbox: {
                    show: true,
                    feature: {
                        saveAsImage: {
                            show:true,
                            excludeComponents :['toolbox'],
                            pixelRatio: 2
                        }
                    }
                },
                dataZoom: [
                     {
                        type: 'slider',
                        filterMode: 'weakFilter',
                        showDataShadow: false,
                        top: 400,
                        height: 10,
                        borderColor: 'transparent',
                        backgroundColor: '#e2e2e2',
                        handleIcon: 'M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z', // jshint ignore:line
                        handleSize: 20,
                        handleStyle: {
                            shadowBlur: 6,
                            shadowOffsetX: 1,
                            shadowOffsetY: 2,
                            shadowColor: '#aaa'
                        },
                        labelFormatter: ''
                    },
                    {
                        type: 'inside',
                        filterMode: 'weakFilter'
                    },
                    {
                        show: true,
                        yAxisIndex: 0,
                        filterMode: 'empty',
                        width: 30,
                        height: '80%',
                        showDataShadow: false,
                        left: '93%'
                    }
                ],
                grid: {
                    height:300
                },
                xAxis: {
                    min: 57600 * 1000,
                    max: (24 * 3600 + 57600) * 1000,
                    scale: true,
                    axisLabel: {
                        formatter: function (val) {
                            return new Date(val).Format("HH:mm");
                        }
                    }
                },
                yAxis: {
                    data: datelist
                },
                series: [{
                    type: 'custom',
                    renderItem: renderItem,
                    itemStyle: {
                        normal: {
                            opacity: 0.8
                        }
                    },
                    encode: {
                        x: [1, 2],
                        y: 0
                    },
                    data: data
                }]
            };

            myChart.setOption(option);
        },
        showechart0: function () {
            //showechart和showechart0一樣
            Date.prototype.Format = function (fmt) {
                var o = {
                    "M+": this.getMonth() + 1, //月份
                    "d+": this.getDate(), //日
                    "H+": this.getHours(), //小時
                    "m+": this.getMinutes(), //分
                    "s+": this.getSeconds(), //秒
                    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
                    "S": this.getMilliseconds() //毫秒
                };
                if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
                for (var k in o)
                    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
                return fmt;
            };

            var myChart = Echarts.init(document.getElementById('echart'), 'walden');

            var datelist = [];
            var size = Statsdata.list.length;
            if (size > 0) {
                var i = 0;
                var last = '';
                for (i = 0; i < Statsdata.list.length; i++) {
                    var d = Statsdata.list[i].d;
                    if (last != d) {
                        last = d;
                        datelist.push(d);
                    }
                }
            }

            var now = new Date();//當前日期
            var data = [];

            var device_id = Statsdata.row.id;

            Echarts.util.each(Statsdata.list, function (w, index) {

                var date = new Date(parseInt(w.dateInfo));
                var date0 = new Date(date.getFullYear(), date.getMonth(), date.getDate());

                var day = date.getDay();//0~6 一周

                var start0 = date0.getTime();//當天0點
                var start = parseInt(w.dateInfo) - start0 + 16 * 3600 * 1000;//毫秒
                var xx = new Date(start).Format("HH:mm:ss");
                var dt = w.dt.split(":");//18:55:26

                var end = start + 1000;
                if (dt.length == 3) {
                    end = start + (parseInt(dt[0]) * 3600 + parseInt(dt[1]) * 60 + parseInt(dt[2])) * 1000;
                }

                var index = 0;
                for (i = 0; i < datelist.length; i++) {
                    if (datelist[i] == w.d) {
                        index = i;
                        break;
                    }
                }

                var color = '#00aa00';
                if (day == 0 || day == 6) {
                    if (device_id == w.device_id) {
                        color = '#aaaa00';
                    } else {
                        color = '#aa00bb';
                    }
                } else {
                    if (device_id == w.device_id) {
                        color = '#00aa00';
                    } else {
                        color = '#0000bb';
                    }
                }

                data.push({
                    name: "(id=" + w.id + ") " + w.dt,
                    value: [
                        index,
                        start,
                        end,
                        new Date(start).Format("HH:mm:ss") + "~" + new Date(end).Format("HH:mm:ss")
                    ],
                    itemStyle: {
                        normal: {
                            color: color
                        }
                    }
                });

                if (index == 0) {
                    console.log("111111----" + index);
                    console.log(data);
                }

            });

            function renderItem(params, api) {
                var categoryIndex = api.value(0);
                var start = api.coord([api.value(1), categoryIndex]);
                var end = api.coord([api.value(2), categoryIndex]);
                var height = api.size([0, 1])[1] * 0.6;

                var rectShape = Echarts.graphic.clipRectByRect({
                    x: start[0],
                    y: start[1] - height / 2,
                    width: end[0] - start[0],
                    height: height
                }, {
                    x: params.coordSys.x,
                    y: params.coordSys.y,
                    width: params.coordSys.width,
                    height: params.coordSys.height
                });

                return rectShape && {
                        type: 'rect',
                        shape: rectShape,
                        style: api.style()
                    };
            }

            option = {
                tooltip: {
                    formatter: function (params) {
                        return params.marker + params.name + ' [' + params.value[3] + "]";
                        //return params.name;
                    }
                },
                title: {
                    text: Statsdata.row.anchang.name + ">" + Statsdata.row.name + " - " + Statsdata.row.selfname + "[" + Statsdata.row.deviceid + "] + " + Statsdata.row.glsb,
                    left: 'center'
                },
                toolbox: {
                    show: true,
                    feature: {
                        saveAsImage: {
                            show:true,
                            excludeComponents :['toolbox'],
                            pixelRatio: 2
                        }
                    }
                },
                dataZoom: [{
                    type: 'slider',
                    filterMode: 'weakFilter',
                    showDataShadow: false,
                    top: 400,
                    height: 10,
                    borderColor: 'transparent',
                    backgroundColor: '#e2e2e2',
                    handleIcon: 'M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z', // jshint ignore:line
                    handleSize: 20,
                    handleStyle: {
                        shadowBlur: 6,
                        shadowOffsetX: 1,
                        shadowOffsetY: 2,
                        shadowColor: '#aaa'
                    },
                    labelFormatter: ''
                }, {
                    type: 'inside',
                    filterMode: 'weakFilter'
                }],
                grid: {
                    height:300
                },
                xAxis: {
                    min: 16 * 3600 * 1000,
                    scale: true,
                    axisLabel: {
                        formatter: function (val) {
                            return new Date(val).Format("HH:mm");
                        }
                    }
                },
                yAxis: {
                    data: datelist
                },
                series: [{
                    type: 'custom',
                    renderItem: renderItem,
                    itemStyle: {
                        normal: {
                            opacity: 0.8
                        }
                    },
                    encode: {
                        x: [1, 2],
                        y: 0
                    },
                    data: data
                }]
            };

            myChart.setOption(option);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        txsz: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            showMonthFirstDay: function () {
                var Nowdate = new Date();
                var MonthFirstDay = new Date(Nowdate.getFullYear(), Nowdate.getMonth(), 1);
                M = Number(MonthFirstDay.getMonth()) + 1
                return MonthFirstDay.getFullYear() + "-" + M + "-" + MonthFirstDay.getDate() + ' 00:00:00';
            },
            showMonthLastDay: function () {
                var Nowdate = new Date();
                var MonthNextFirstDay = new Date(Nowdate.getFullYear(), Nowdate.getMonth() + 1, 1);
                var MonthLastDay = new Date(MonthNextFirstDay - 86400000);
                M = Number(MonthLastDay.getMonth()) + 1
                return MonthLastDay.getFullYear() + "-" + M + "-" + MonthLastDay.getDate() + ' 23:59:59';
            },
            defaultdate2: function () {
                var MonthFirstDay = Controller.api.showMonthFirstDay();
                var MonthLastDay = Controller.api.showMonthLastDay();

                return MonthFirstDay + " - " + MonthLastDay;
            },
            formatter: {//渲染的方法
                zxstatus: function (value, row, index) {
                    //Controller.api.formatter.zxstatus
                    if (value == 0) {
                        return [
                            '<a href="javascript:;" class="bg-red-gradient"> 離線 </a>'
                        ].join("")

                    } else {
                        return [
                            '<a href="javascript:;" class="bg-green"> 在線 </a>'
                        ].join("")
                    }
                },
                onlinetime: function (value, row, index) {
                    var online_starttime = row.online_starttime;
                    var nowtime = new Date().getTime() / 1000;

                    if (online_starttime > 0) {
                        var s = nowtime - online_starttime;
                        var hour = Math.floor(s / 3600);
                        var min = Math.floor((s - hour * 3600) / 60);
                        var sec = Math.floor(s % 60);
                        var str = hour + " : " + min + " : " + sec;
                        return [
                            '<a href="javascript:;"> ' + str + ' </a>'
                        ].join("")
                    } else {
                        return [
                            '<a href="javascript:;"> -- </a>'
                        ].join("")
                    }
                },
            }
        }
    };
    return Controller;
});